﻿#ifndef CCapControl_H
#define CCapControl_H
#include <QThread>
#include <QMutex>
#include <QMutexLocker>
#include <QQueue>
#include <QApplication>
#include <QMutex>
#include <QUdpSocket>
#include <QtSerialPort/QSerialPort>
#include "common/headerfile.h"
#include "configprocess.h"
#include "capcontroldefine.h"


class CCapControl : public QThread
{
    Q_OBJECT
public:
    explicit CCapControl(QObject *parent = 0);
    ~CCapControl();

    void run();

    bool startRcvData(QString sComNo,int bandNum);

    static CCapControl *_pInstance;
    static  CCapControl* getInstance();

    QSerialPort* m_pSerialPort;

    bool m_bConnect;


signals:

    void signal_rcvthresholddata(QVariant var);

    void signal_rcvpiddata(QVariant var);

    void signal_showPID(int cmdid,float lfKp,float lfKi,float lfKd);

    void signal_showloopdata(QVariant var);


public slots:

    void getAxisParam(int i32AxisNo,int i32Cmdid);
    bool setAxisParam(int i32AxisNo,int nType,float lfparam);


public:


    void setUnlockCmd(int cmdid,int value);
    void setAxisHandShakeParam(int i32AxisNo,int i32value,int datalen);
    bool setThresholdParam(int i32AxisNo,int i32Cmdid,int i32Value,int datalen);
    bool getThresholdParam(int i32AxisNo,int i32Cmdid);

    void startGroudTest(int i32AxisNo,int i32Mode,int data0,int data1);
    uchar caclchecksum(uchar* pdata,int i32datalen);

    void addSendData(char* pdata,int nlen);

    void parseRcvData(char* pdata,int nlen);


private:


    QList<QByteArray> _senddatalist;

    QMap<qint64,QByteArray> _rcvFramelist;


    QMutex _senddataLocker;

    QMutex _rcvdataLocker;


    bool _bStartRcvData;
    QString _sComNo;
    int _i32BandNum;
    int _i32FrameCnt;

    QByteArray m_sRcvData;

    quint64 _i64frameId;

    QTimer* _pStatusTimer;

    int _i32GetParamCnt;



};

#endif // QCameraCTRL_H
